<?php
//***************  add by code   ******************
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of article
 *
 * @author Administrator
 */
class lianxiwomen extends CI_Controller {

    private $page_size=10;

    public function __construct() {
        parent::__construct();
        $this->url = $this->uri->segments;
        $this->CI = & get_instance();
    }

    public function index() {
        $g_nav_list = $this->CI->load->get_var('g_nav_list');//获取导航
        $url_info = $this->url;
        $action = $url_info[2];
        $data['action_info'] = $this->m_public->getRowInfo('class',array('classlinkname'=>$action));

        /*SEO部分*/
        if(isset($data['action_info']['seotitle']) && !empty($data['action_info']['seotitle']))
            $data['g_site']['websitename'] = $data['action_info']['seotitle'];
        if(isset($data['action_info']['keywords']) && !empty($data['action_info']['keywords']))
            $data['g_site']['websitekeywords'] = $data['action_info']['keywords'];
        if(isset($data['action_info']['description']) && !empty($data['action_info']['description']))
            $data['g_site']['websitedescription'] = $data['action_info']['description'];

        /*右侧部分，产品*/
        $condition['from'] = 'class';
        $condition['where'] = array(
            'classpropertyid' => 20,
            'configid' => CONFIG_ID,
//            'parentid' => 3
        );
        $condition['limit'] = 3;
        $condition['offset'] = 0;
        $condition['order'] = 'listid';
        $data['products'] = $this->m_public->get_list($condition);

        $contact_config = $this->m_public->getRowInfo('config',array('configid'=>CONFIG_ID),'contact_config,mailreceiveaddressforfeedback');
        $data['contact'] = json_decode($contact_config['contact_config'],true);
        $data['contact']['email'] = $contact_config['mailreceiveaddressforfeedback'];

        /*头部,底部数据*/
        $config = $this->m_public->getRowInfo('config',array('configid'=>CONFIG_ID),'copyright,banquan,contact_config,footerinfo');
        $config['contact_config'] = json_decode($config['contact_config'],true);
        $data['config'] = $config;
        $footer_condition = array(
            'from' => 'link',
            'where' => array('isclose'=>0,'typeid'=>1,'configid'=>CONFIG_ID),
            'order' => 'listid'
        );
        $data['footer_info'] = $this->m_public->get_list($footer_condition);

        $this->load->view('template_contact',$data);
    }

    public function leave_message(){
        $data = $this->input->post();
        if(trim($data['companyname']) != '' && trim($data['companyname']) != '您公司的名称' && trim($data['nickname']) != '' && trim($data['nickname']) != '您的称呼' && trim($data['telphone']) != '' && trim($data['telphone']) != '您的电话' && trim($data['bookcontent']) != '' && trim($data['bookcontent']) != '留言内容'){
            foreach($data as $key=>$val){
                $data[$key] = $this->lib_replace_end_tag($val);
            }
            $data['addtime'] = date('Y-m-d H:i:s',time());
            $data['ipaddress'] = $this->m_public->get_client_ip();
            $data['isreply'] = 0;
            $data['adminid'] = 0;
            $data['isclose'] = 0;
            $this->m_public->addRowInfo('guestbook',$data);
            echo 0;exit;
        }
    }

    private function lib_replace_end_tag($str){
        if (empty($str)) return false;
        $str = htmlspecialchars($str);
        $str = str_replace( '/', "", $str);
        $str = str_replace("\\", "", $str);
        $str = str_replace(">", "", $str);
        $str = str_replace("<", "", $str);
        $str = str_replace("<SCRIPT>", "", $str);
        $str = str_replace("</SCRIPT>", "", $str);
        $str = str_replace("<script>", "", $str);
        $str = str_replace("</script>", "", $str);
        $str=str_replace("select","select",$str);
        $str=str_replace("join","join",$str);
        $str=str_replace("union","union",$str);
        $str=str_replace("where","where",$str);
        $str=str_replace("insert","insert",$str);
        $str=str_replace("delete","delete",$str);
        $str=str_replace("update","update",$str);
        $str=str_replace("like","like",$str);
        $str=str_replace("drop","drop",$str);
        $str=str_replace("create","create",$str);
        $str=str_replace("modify","modify",$str);
        $str=str_replace("rename","rename",$str);
        $str=str_replace("alter","alter",$str);
        $str=str_replace("cas","cast",$str);
        $str=str_replace("&","&",$str);
        $str=str_replace(">",">",$str);
        $str=str_replace("<","<",$str);
        $str=str_replace(" ",chr(32),$str);
        $str=str_replace(" ",chr(9),$str);
        $str=str_replace("    ",chr(9),$str);
        $str=str_replace("&",chr(34),$str);
        $str=str_replace("'",chr(39),$str);
        $str=str_replace("<br />",chr(13),$str);
        $str=str_replace("''","'",$str);
        $str=str_replace("css","'",$str);
        $str=str_replace("CSS","'",$str);
        return $str;
    }
}
